package hanshunping.project.chatRoom.chatClient.client.service;

import hanshunping.project.chatRoom.common.Message;
import hanshunping.project.chatRoom.common.MessageType;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

/**
 * create by: 蔡博
 * description: TODO
 * create time: 2022/11/20 15:44
 * 消息相关服务方法
  * @Param: null
 * @return
 */
public class MessageService {
    public void senMes(String sid,String gid,String content){
        Message ms = new Message();
        ms.setTime(new Date().toString());
        ms.setGetter(gid);
        ms.setMesType(MessageType.MESSAGE_MES);
        ms.setContent(content);
        ms.setSender(sid);
        try {
            ObjectOutputStream oos = new ObjectOutputStream(ManageConnectThread.getThread(sid).getSocket().getOutputStream());
            oos.writeObject(ms);
            System.out.println(ms.getSender()+"对"+ms.getGetter()+"说："+ms.getContent());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
